import request from '@/utils/request'

export interface OpportunityDTO {
  opportunityId?: string
  opportunityCode: string
  opportunityName: string
  customerId: string
  contactId?: string
  ownerUserId?: string
  ownerDeptId?: string
  stage: 'INITIAL' | 'REQUIREMENT' | 'QUOTE' | 'NEGOTIATE' | 'WIN' | 'LOSE'
  probability?: number
  expectedAmount?: number
  expectedDate?: string
  actualAmount?: number
  actualDate?: string
  source?: string
  competitorInfo?: string
  description?: string
  status?: 'ACTIVE' | 'WON' | 'LOST' | 'CANCELLED'
  winReason?: string
  loseReason?: string
  remark?: string
}

// 销售机会管理API
export function pageOpportunity(params: {
  pageNum: number
  pageSize: number
  opportunityCode?: string
  opportunityName?: string
  customerId?: string
  ownerUserId?: string
  stage?: string
  status?: string
  source?: string
  startTime?: string
  endTime?: string
}) {
  return request({ url: '/crm/opportunity/page', method: 'get', params })
}

export function getOpportunity(id: string) {
  return request({ url: `/crm/opportunity/${id}`, method: 'get' })
}

export function createOpportunity(data: OpportunityDTO) {
  return request({ url: '/crm/opportunity', method: 'post', data })
}

export function updateOpportunity(id: string, data: OpportunityDTO) {
  return request({ url: `/crm/opportunity/${String(id)}`, method: 'put', data })
}

export function deleteOpportunity(id: string) {
  return request({ url: `/crm/opportunity/${String(id)}`, method: 'delete' })
}

export function deleteOpportunityBatch(ids: string[]) {
  return request({ url: '/crm/opportunity/batch-delete', method: 'post', data: ids })
}


